package com.hxgis.statisticanalysis.intelligentIndicator.controller;

import cn.hutool.json.JSONUtil;
import com.hxgis.statisticanalysis.intelligentIndicator.service.MonthReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * @author 赵恒
 * @date 2023/1/4
 */
@RestController
@RequestMapping("/statisticanalysis/frontapi/v1")
@Api(tags = "月报")
@Slf4j
public class MonthReportController {
    @Resource
    MonthReportService monthReportService;

    @RequestMapping(value = "/monthReport/queryAll", method = RequestMethod.GET)
    @ApiOperation("查询业务简报全部表格数据")
    public Map<String, Object> queryAll(String month) {
        log.info("/monthReport/query, 参数：month={}", month);
        return monthReportService.queryAll(month);
    }

    @RequestMapping(value = "/monthReport/updateAll", method = RequestMethod.POST)
    @ApiOperation("修改业务简报全部表格数据")
    public String updateAll(@RequestBody Map<String, Object> map) {
        log.info(JSONUtil.toJsonStr(map));
        monthReportService.updateAll(map);
        return "更新成功";
    }

    @RequestMapping(value = "/monthReport/exportWord", method = RequestMethod.GET)
    @ApiOperation(value = "导出word文档")
    public void exportWord(String month, HttpServletResponse response) {
        if (month == null) {
            throw new RuntimeException("时间不能为空");
        }
        monthReportService.exportWord(month, response);
    }
}
